Skip to content

feat(toggle): add custom checkedIcon and uncheckedIcon support - #31020

Closed
AbdullahAhmadAAK wants to merge 2 commits into
ionic-team:mainfrom
AbdullahAhmadAAK:main
Closed

AbdullahAhmadAAK wants to merge 2 commits into
ionic-team:mainfrom
AbdullahAhmadAAK:main

Conversation

@AbdullahAhmadAAK

Copy link
Copy Markdown

Issue number: resolves #30996


What is the current behavior?

ion-toggle uses fixed built-in on/off icons when enableOnOffLabels is enabled, and there is no way to override those icons globally or per component instance.

What is the new behavior?

This PR adds customizable toggle icons with a clear fallback order:

  • Adds per-component props: checkedIcon and uncheckedIcon on [ion-toggle].
  • Adds global config options: toggleCheckedIcon and toggleUncheckedIcon
  • Uses precedence: component props override global config, and global config overrides existing mode defaults.
  • Keeps existing defaults unchanged when no custom icons are provided. Proper stylings done for the icons to adjust in toggle.
  • Adds unit tests covering prop-over-config precedence and default fallback behavior for both iOS and MD

Does this introduce a breaking change?

  • No

This is a non-breaking feature enhancement focused on toggle icon customization and test coverage only.

Screenshot of how it looks
image

Video : https://github.com/user-attachments/assets/a8a103dc-d6b1-4b81-be65-baa5b476a379

@AbdullahAhmadAAK
AbdullahAhmadAAK requested a review from a team as a code owner March 19, 2026 01:57
@vercel

vercel Bot commented Mar 19, 2026

Copy link
Copy Markdown

@AbdullahAhmadAAK is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added package: core @ionic/core package package: angular @ionic/angular package package: vue @ionic/vue package labels Mar 19, 2026

@NyaomiDEV NyaomiDEV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about this stuff.

}

.toggle-inner .toggle-switch-icon {
@include padding(1px);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stay.

Comment on lines +69 to +73
min-width: var(--on-off-label-icon-size);
min-height: var(--on-off-label-icon-size);
display: block;
opacity: 0.86;
transition: transform $toggle-md-transition-duration, opacity $toggle-md-transition-duration, color $toggle-md-transition-duration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there a reason to include min-{width,height}, display, opacity and transition, though? It should've been already styled as icon support was already there.

Comment on lines +65 to +66


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newlines?

<div class="grid-item">
<h2>Unchecked</h2>
<ion-toggle>Enable Notifications</ion-toggle>
<ion-toggle >Enable Notifications</ion-toggle>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space which would look bad?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@AbdullahAhmadAAK

Copy link
Copy Markdown
Author

Hi @NyaomiDEV , I've made the required changes according to your review.

@NyaomiDEV

Copy link
Copy Markdown

It would look good to me, however I think the Ionic team should check it too.

@ShaneK

ShaneK commented Nov 18, 2026

Copy link
Copy Markdown
Member

Hey @AbdullahAhmadAAK! Thanks for the PR! I've opened #31774 to carry this forward, so I'm going to close this one in favor of it.

New features now go to the feature-9.1 branch instead of main, which didn't exist when you opened this, so that's not on you. Retargeting would have conflicted because the generated Angular proxies moved on that branch, so it was easier to start fresh from feature-9.1 and bring your commit over as is. You're still the author of it, so you'll get credit when it merges. I added a few commits on top that fix the size of the custom checked icon in ios, keep the md icon at its current size and add tests.

Thanks again for getting this started! 💪

@ShaneK ShaneK closed this Nov 18, 2026
ShaneK added a commit that referenced this pull request Nov 24, 2026
Issue number: resolves #30996

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Currently, the on/off label icons in `ion-toggle` are hardcoded per
mode, so there's no way to swap them for something like a sun and moon
on a dark mode toggle.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Added `checkedIcon` and `uncheckedIcon` props to `ion-toggle`, plus
`toggleCheckedIcon` and `toggleUncheckedIcon` global config options. The
props win over the config, and both fall back to the existing mode
defaults. Like the defaults, they only show when `enableOnOffLabels` is
`true`.
- In `ios`, the default checked icon is a dash rotated into a vertical
line, so a custom checked icon skips that rotation and uses the same
size and inset as the unchecked icon.
- Added both props to the standalone Angular `IonToggle` inputs, since
those aren't generated.

## Does this introduce a breaking change?

- [ ] Yes
- [X] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->

It's a new feature, which is why it's pointed at `feature-9.1`.

## Other information

This is based on [the original
PR](#31020) by
@AbdullahAhmadAAK. That PR pointed at `main`, but new features now go to
`feature-9.1`, a branch that didn't exist yet when it was opened.
Retargeting it would have conflicted, because the generated Angular
proxies moved on `feature-9.1`, so I remade it from `feature-9.1`
instead. Their commit is still there with them as the author. The
commits after it fix the `ios` checked icon size, keep the `md` icon at
its current size and add tests. Thanks to @AbdullahAhmadAAK for getting
this started!

[Custom icons test page
(MD)](https://ionic-framework-git-fw-7639-ionic1.vercel.app/src/components/toggle/test/custom-icons?ionic:mode=md)
[Custom icons test page
(iOS)](https://ionic-framework-git-fw-7639-ionic1.vercel.app/src/components/toggle/test/custom-icons?ionic:mode=ios)

---------

Co-authored-by: AbdullahAhmadAAK <Abdullahaak06@gmail.com>
Co-authored-by: ionitron <hi@ionicframework.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package package: vue @ionic/vue package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: ion-toggle: Custom on/off icons

3 participants